{% extends TEMPLATE_BASE %}

{% block title %}Voters &amp; Ballot Tracking Center for {{election.name}}{% endblock %}
{% block content %}
  <h3 class="title">{{election.name}} &mdash; 选民与选票追踪中心 <span style="font-size:0.7em;">[<a href="{% url "election@view" election.uuid %}">返回选举页面</a>]</span></h3>

<p>
<b>谁可以进行投票?</b>
{% if election.openreg %}
{{election.pretty_eligibility|safe}}
{% else %}
<em>此处只展示选民</em>.
{% endif %}
</p>

{% if admin_p and not election.frozen_at %}
{% if election.private_p %}
<em>您的选举被标记为私有，这意味着您无法更广泛地开放注册</em>.<br />
{% else %}
<form method="post" action="{% url "election@voters@eligibility" election.uuid %}">
<input type="hidden" name="csrf_token" value="{{csrf_token}}" />
<input type="radio" name="eligibility" value="openreg" {% if election.openreg and not election.eligibility %}CHECKED{% endif %} /> 任何人均可投票<br />
<input type="radio" name="eligibility" value="closedreg" {% if not election.openreg %}CHECKED{% endif %} /> 只有下面明确列出的选民可以投票<br />
{% if categories %}
<input type="radio" name="eligibility" value="limitedreg" {% if election.eligibility %}CHECKED{% endif %} /> 只有是以下成员之一的选民
<select name="category_id">
{% for category in categories %}
<option value="{{category.id}}" {% if eligibility_category_id == category.id %}SELECTED{% endif %}> {{category.name}}</option>
{% endfor %}
</select>
<br />
{% endif %}
<input class="button" type="submit" value="update" />
</form>
{% endif %}
{% endif %}

{% if email_voters and election.frozen_at and admin_p %}
<p><a class="button" href="{% url "election@voters@email" election.uuid %}">邮件联系选民</a></p>
{% endif %}

{% if election.num_voters > 20 %}
<p>
{% if q %}
<p><em>搜索 <u>{{q}}</u>.</em> [<a href="?">清除搜索</a>]</p>
{% else %}
<form method="get" action="{% url "election@voters@list-pretty" election.uuid %}"><b>search</b>: <input type="text" name="q" /> <input type="submit" value="search" /></form>
{% endif %}
</p>
{% endif %}

{% if admin_p %}
<!-- Add a Voter: WORK HERE-->
{% if upload_p and not election.openreg %}
<p>
<a class="button" href="{% url "election@voters@upload" election_uuid=election.uuid %}">批量上传选民</a>
</p>

{% if voter_files %}
Prior Bulk Uploads:
<ul>
{% for vf in voter_files %}
<li>
{% if vf.voter_file %}
{{vf.voter_file.size}}
{% else %}
{{vf.voter_file_content|length}}
{% endif %}
 bytes, at {{vf.uploaded_at}}:
{% if vf.processing_finished_at %}
<em>done processing: {{vf.num_voters}} voters loaded</em>
{% else %}

{% if vf.processing_started_at %}
<em>currently processing</em>
{% else %}
<em>not yet processed</em>
{% endif %}

{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endif %}
{% endif %}

{% if voters %}

<p>
<b>
{% if election.num_cast_votes %}
{{election.num_cast_votes}} cast vote{% ifequal election.num_cast_votes 1 %}{% else %}s{% endifequal %}
{% else %}
no votes yet
{% endif %}
</b>
</p>

{% if voters_page.has_previous %}
<a href="{% url "election@voters@list-pretty" election.uuid %}?page={{voters_page.previous_page_number}}&limit={{limit}}&q={{q|urlencode}}">previous {{limit}}</a> &nbsp;&nbsp;
{% endif %}


Voters {{voters_page.start_index}} - {{voters_page.end_index}} (of {{total_voters}})&nbsp;&nbsp;

{% if voters_page.has_next %}
<a href="{% url "election@voters@list-pretty" election.uuid %}?page={{voters_page.next_page_number}}&limit={{limit}}&q={{q|urlencode}}">next {{limit}}</a> &nbsp;&nbsp;
{% endif %}

<table class="pretty">
<tr>
{% if admin_p or not election.use_voter_aliases %}
{% if admin_p %}
<th style="width: 80px;">Actions</th>
<th>Login</th>
<th>Email Address</th>
{% endif %}
<th>Name</th>
{% endif %}

{% if election.use_voter_aliases %}
<th>Alias</th>
{% endif %}
<th>Smart Ballot Tracker</th>
</tr>
{% for voter in voters %}
<tr>
{% if admin_p or not election.use_voter_aliases %}
{% if admin_p %}
<td style="white-space: nowrap;">
{% if election.frozen_at %}
[<a href="{% url "election@voters@email" election.uuid %}?voter_id={{voter.voter_login_id}}">email</a>]
{% endif %}
[<a onclick="return confirm('are you sure you want to remove {{voter.name}} ?');" href="{% url "election@voter@delete" election.uuid voter.uuid %}">x</a>]
</td>
<td>{{voter.voter_login_id}}</td>
<td>{{voter.voter_email}}</td>
{% endif %}
<td><img class="small-logo" src="/static/auth/login-icons/{{voter.voter_type}}.png" alt="{{voter.voter_type}}" /> {{voter.name}}</td>
{% endif %}
{% if election.use_voter_aliases %}
<td>{{voter.alias}}</td>
{% endif %}
<td><tt style="font-size: 1.4em;">{% if voter.vote_hash %}{{voter.vote_hash}} <span style="font-size:0.8em;"><!-- no link for now --></span>{% else %}&mdash;{% endif %}</tt></td>
</tr>
{% endfor %}
</table>

{% else %}
<br /><br />
<em>no voters.</em>
{% endif %}

{% endblock %}
